//
//  WBNavigationController.swift
//  Weibo
//
//  Created by kobe on 2016/12/22.
//  Copyright © 2016年 kobe. All rights reserved.
//

import UIKit

class WBNavigationController: UINavigationController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //隐藏默认的NavigationBar
        navigationBar.isHidden = true
        
    }

    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        //如果不是栈底控制器才需要隐藏 根控制器不需要处理
        if childViewControllers.count > 0 {
            viewController.hidesBottomBarWhenPushed = true
            
            //判断控制器的类型
            if let vc = viewController as? WBBaseViewController {
                
                var title = "返回"
                
                //判断控制器的级数
                if childViewControllers.count == 1 {
                    //title显示首页标题
                    title = childViewControllers.first?.title ?? "返回"
                }
                
                
                //取出自定义的navItem
                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, fontSize: 16, target: self, action: #selector(back),isBack:true)
                
            }
            
        }
        
        
        
        super.pushViewController(viewController, animated: true)
//        viewController.hidesBottomBarWhenPushed = false
    }
    
    @objc private func back() {
        popViewController(animated: true)
    }

}
